 package deleteface.bank.jqsoft.cn.deleteface;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AppOpsManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.provider.Contacts;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qw.soul.permission.SoulPermission;
import com.qw.soul.permission.bean.Permission;
import com.qw.soul.permission.bean.Permissions;
import com.qw.soul.permission.bean.Special;
import com.qw.soul.permission.callbcak.CheckRequestPermissionsListener;
import com.qw.soul.permission.callbcak.SpecialPermissionListener;
import com.tbruyelle.rxpermissions2.RxPermissions;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.request.RequestCall;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.net.URLEncoder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;


import javax.inject.Inject;

import cn.jqsoft.bank.deleteface.R;
import deleteface.bank.jqsoft.cn.deleteface.base.AbstractActivity;
import deleteface.bank.jqsoft.cn.deleteface.base.BphsConstants;
import deleteface.bank.jqsoft.cn.deleteface.http.BasePresenter;
import deleteface.bank.jqsoft.cn.deleteface.http.contract.HeadCollectContract;
import deleteface.bank.jqsoft.cn.deleteface.http.contract.HttpResultBaseGWBean;
import deleteface.bank.jqsoft.cn.deleteface.http.contract.PeopleBaseFragmentContract;
import deleteface.bank.jqsoft.cn.deleteface.http.contract.PeopleBaseInfoFragmentModule;
import deleteface.bank.jqsoft.cn.deleteface.http.presenter.HeadCollectPresenter;
import deleteface.bank.jqsoft.cn.deleteface.http.presenter.PeopleBaseFragmentPresenter;
import deleteface.bank.jqsoft.cn.deleteface.setip.SettingServerActivity;
import deleteface.bank.jqsoft.cn.deleteface.setip.Util;
import deleteface.bank.jqsoft.cn.deleteface.ui.NbButton;
import deleteface.bank.jqsoft.cn.deleteface.ui.WebServiceUtils;

import deleteface.bank.jqsoft.cn.deleteface.webservice.Node;
import io.reactivex.functions.Consumer;
import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.logging.HttpLoggingInterceptor;

public class MainActivity extends AbstractActivity implements PeopleBaseFragmentContract.View {
    RequestCall call;
    NbButton btnDeleteArchive,btn_delete_time,btn_setting;
    Button btn_add_area,btn_ip_list;
    EditText etIdCardToDelete;
    TextView ip_address,ip_time;
    ArrayList<IpBean> urlList=new ArrayList<>();
    ArrayList<IpBean> timeurlList=new ArrayList<>();
    String timeurl="";
    String url = "";
    String message;
    AlertDialog dialog;
    String[] item;
    private EditText et_reason_for_delete;
    private ImageView iv_passin_head;
    private TextView tx_version;
    private Button bt_username_clear;
    private TagFlowLayout search_page_flowlayout;

    @Inject
    PeopleBaseFragmentPresenter mPresenter;
    /**
     * 获取本地软件版本号名称
     */
    public static String getLocalVersionName(Context ctx) {
        String localVersion = "";
        try {
            PackageInfo packageInfo = ctx.getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(ctx.getPackageName(), 0);
            localVersion = packageInfo.versionName;

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tx_version=(TextView)findViewById(R.id.tx_version);
        btn_setting=(NbButton)findViewById(R.id.btn_setting);
        tx_version.setText("当前版本号："+getLocalVersionName(this));

//        setInstallPermission();
        RxPermissions rxPermissions = new RxPermissions(MainActivity.this);
        rxPermissions.requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.SYSTEM_ALERT_WINDOW, Manifest.permission.READ_EXTERNAL_STORAGE)
                .subscribe(new Consumer<com.tbruyelle.rxpermissions2.Permission>() {
                    @Override
                    public void accept(com.tbruyelle.rxpermissions2.Permission permission) throws Exception {
                        if (permission.granted) {
//                        show("用户给权限啦");
//                            Toast.makeText(MainActivity.this, "用户给权限啦", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        if (permission.shouldShowRequestPermissionRationale) {
//                        show("用户不给权限");
                            Toast.makeText(MainActivity.this, "用户不给权限", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        Toast.makeText(MainActivity.this, "弹窗不显示", Toast.LENGTH_SHORT).show();
//                    show("弹窗不显示");
                    }
                });

//        requestPermission();
//        checkFloatPermission(MainActivity.this);

        SharedPreferences sp = getSharedPreferences("SP_IPBEAN_List",Activity.MODE_PRIVATE);//创建sp对象,如果有key为"SP_PEOPLE"的sp就取出
        Gson gson = new Gson();
        String jsonStr=gson.toJson(urlList); //将List转换成Json
        String   peopleListJson = sp.getString("KEY_PEOPLE_LIST_DATA",jsonStr);  //取出key为"KEY_PEOPLE_DATA"的值，如果值为空，则将第二个参数作为默认值赋值
        if(peopleListJson!="")  //防空判断
        {
            Gson gson1 = new Gson();
            urlList = gson1.fromJson(peopleListJson, new TypeToken<List<IpBean>>() {}.getType()); //将json字符串转换成List集合
        }
        search_page_flowlayout=(TagFlowLayout)findViewById(R.id.search_page_flowlayout);
        bt_username_clear=(Button)findViewById(R.id.bt_username_clear);
        btnDeleteArchive=(NbButton)findViewById(R.id.btn_delete_archive);

        etIdCardToDelete=(EditText)findViewById(R.id.et_id_card_to_delete);
        ip_address=(TextView)findViewById(R.id.ip_address);
        btn_delete_time=(NbButton)findViewById(R.id.btn_delete_time);
        btn_add_area=(Button)findViewById(R.id.btn_add_area);
        ip_time=(TextView)findViewById(R.id.ip_time);
        btn_ip_list=(Button)findViewById(R.id.btn_ip_list);
        et_reason_for_delete=(EditText)findViewById(R.id.et_reason_for_delete);
        iv_passin_head=(ImageView)findViewById(R.id.iv_passin_head);
        btn_add_area.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog();
            }
        });

//        ip_address.setText("本溪"+"底片地址:"+"114.215.197.163:8801");
//        ip_time.setText("本溪"+"有效期地址:"+"114.215.197.163:9099");
//        url="http://"+"114.215.197.163:8801"+"/";
//        timeurl="http://"+"114.215.197.163:9099"+"/WebService/Andrews/SaveFaceRecognitionDay.asmx";


        btnDeleteArchive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                btnDeleteArchive.startAnim();
                if ( TextUtils.isEmpty(etIdCardToDelete.getText().toString())||TextUtils.isEmpty(url)){

                    Toast.makeText(MainActivity.this,"身份证号和地址不能为空!",Toast.LENGTH_SHORT).show();
                    btnDeleteArchive.end("删除人脸档案");
                }else if( TextUtils.isEmpty(et_reason_for_delete.getText().toString())){
                    Toast.makeText(MainActivity.this,"请输入删除原因,手动填写或者快捷填写!",Toast.LENGTH_SHORT).show();
                    btnDeleteArchive.end("删除人脸档案");
                }else {
                    loadIDCardNumberHeadImageInfo(etIdCardToDelete.getText().toString());
                    btnDeleteArchive.end("删除人脸档案");
                }




            }
        });
        item=new String[urlList.size()];
        for (int i=0;i<urlList.size();i++){
            item[i]= urlList.get(i).getAddress();
        }

        ip_address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                startActivityForResult(new Intent(MainActivity.this, SettingServerActivity.class), 1);

            }
        });

        /**
         * 有效期
         * */
        ip_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivityForResult(new Intent(MainActivity.this, SettingServerActivity.class), 1);

            }
        });

        btn_delete_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn_delete_time.startAnim();
                deleteTime();
//                new Thread(netReadCard).start();
                btn_delete_time.end("删除有效期");
            }
        });

        initdatasing();

        Beta.checkUpgrade();

        bt_username_clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                etIdCardToDelete.setText("");
            }
        });

        btn_setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    requestAlertWindowPermission();
                }
            }
        });

    }

    @Override
    protected void loadData() {

    }

    private String baseurl="";
    /**
     * 为了得到传回的数据，必须在前面的Activity中（指MainActivity类）重写onActivityResult方法
     *
     * requestCode 请求码，即调用startActivityForResult()传递过去的值
     * resultCode 结果码，结果码用于标识返回数据来自哪个新Activity
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String resultip = data.getExtras().getString("ip");//得到新Activity 关闭后返回的数据
        String resulttermip = data.getExtras().getString("termip");//得到新Activity 关闭后返回的数据
        String resultadress= data.getExtras().getString("address");//得到新Activity 关闭后返回的数据
        if(TextUtils.isEmpty(resultip ) ||TextUtils.isEmpty(resulttermip )  ){

        }else {
            ip_address.setText(resultadress+"底片地址:"+resultip);
            ip_time.setText(resultadress+"有效期地址:"+resulttermip);
            url="http://"+resultip+"/";
            baseurl="http://"+resulttermip+"/";
            timeurl="http://"+resulttermip+"/WebService/Andrews/SaveFaceRecognitionDay.asmx";
        }

    }


    @RequiresApi(api = Build.VERSION_CODES.M)
    private void requestAlertWindowPermission() {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
        intent.setData(Uri.parse("package:" + getPackageName()));
        startActivityForResult(intent, 102);
    }




    String DeleteBasePhotoMessage,DeleteTimeMessage;
    private final int DELETETIME_MESSAGE=2;
    /**
     * 删除有效期
     */

    private void deleteTime(){
        String DeleteBitmapUrl=timeurl;
        String methodName="DeleteWPReadCardInfo" ;
        String idCardNumber =etIdCardToDelete.getText().toString();
        if ( TextUtils.isEmpty(idCardNumber)||TextUtils.isEmpty(timeurl)){
            myhandler.sendEmptyMessage(1);
//            btn_delete_time.end("删除有效期");
        }else {
            JSONObject data = new JSONObject();
            try {
                data.put("sCardNo",getBase64String(idCardNumber));

                data.put("iCollectionType",getBase64String("5"));//类型(1:人脸识别 2: 人证核验 3:身份证 4:删除人脸记录 5:删除有效期记录) (Base64加密)
                data.put("sLoginName",getBase64String("DeleteTool"));//用户登录名 (Base64加密)

//                data.put("sPersonID",sPersonID);

            } catch (JSONException e) {
                e.printStackTrace();
            }




            if(BphsConstants.appweburltype==2){
                String request = Node.getRequestParams(methodName, data.toString(),idCardNumber);
                mPresenter.deleteWPReadCardInfoGuizhou(request,baseurl);
            }else {
                String request = Node.getRequestParams(methodName, data.toString(), idCardNumber);
                mPresenter.deleteWPReadCardInfo(request,baseurl);
            }

        }

    }


    public static Object JSONToObject(String json,Class beanClass) {
        Gson gson = new Gson();
        return gson.fromJson(json, beanClass);
    }
    /**
     * 删除人脸档案
     */

    private void deleteArchive(){

        String idCardNumber =etIdCardToDelete.getText().toString().trim();
        String deleteArchiveUrl=url+"delete";
        if ( TextUtils.isEmpty(idCardNumber)||TextUtils.isEmpty(url)){

            Toast.makeText(this,"身份证号和地址不能为空!",Toast.LENGTH_SHORT).show();
            btnDeleteArchive.end("删除人脸档案");
        }else {

            long timestamp =getTimeStamp();
            String timestampString = String.valueOf(timestamp);
            String token = getProcessedToken(timestamp);
            Map<String, String> params = new HashMap<>();
            params.put("acs_token", token);
            params.put("acs_time", timestampString);
            params.put("idnum", idCardNumber);

            call = OkHttpUtils.post()//
                    .url(deleteArchiveUrl)//
                    .params(params)//
                    .build();//
            call.execute(new MyResultCallback<VerifyResultBean>() {

                @Override
                public void onSuccess(VerifyResultBean response) {
                    if (response!=null && "1".equals(response.getRespond())){
                        Toast.makeText(MainActivity.this,"删除人脸档案成功",Toast.LENGTH_SHORT).show();
                        btnDeleteArchive.end("删除人脸档案");
                        deletephoto();
//                        new Thread(runNote).start();
                    } else {
                        String suffix = "";
                        if (response!=null){
                            suffix=":"+response.getMessage();
                        }

                        Toast.makeText(MainActivity.this,"删除人脸档案失败",Toast.LENGTH_SHORT).show();
                        btnDeleteArchive.end("删除人脸档案");
                    }
                }

                @Override
                public void onFailure(Exception e) {

                    Toast.makeText(MainActivity.this,"删除人脸档案失败"+e.getMessage(),Toast.LENGTH_SHORT).show();

                }
            });

        }



    }

    AlertDialog dialogPhone;
    private void showDialog() {
        final EditText edit_newname, edit_newip1,edit_newip2,edit_newip3,edit_newip4;

        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.add_newarea_layout, null);
        edit_newname = (EditText) view.findViewById(R.id.edit_newname);
        edit_newip1 = (EditText) view.findViewById(R.id.edit_newip1);
        edit_newip2 = (EditText) view.findViewById(R.id.edit_newip2);
        edit_newip3 = (EditText) view.findViewById(R.id.edit_newip3);
        edit_newip4 = (EditText) view.findViewById(R.id.edit_newip4);




        dialogPhone = new AlertDialog.Builder(this).setPositiveButton("确定", null).setNegativeButton("取消", null).create();
        dialogPhone.setTitle("添加新地址");// 设置标题
        dialogPhone.setView(view);
        dialogPhone.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button positionButton = dialogPhone.getButton(AlertDialog.BUTTON_POSITIVE);
                Button negativeButton = dialogPhone.getButton(AlertDialog.BUTTON_NEGATIVE);
                positionButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (!TextUtils.isEmpty(edit_newip1.getText().toString())&&
                                !TextUtils.isEmpty(edit_newip2.getText().toString())&&
                                !TextUtils.isEmpty(edit_newip3.getText().toString())&&
                                !TextUtils.isEmpty(edit_newip4.getText().toString())
                                ) {
                         String newip1 = edit_newip1.getText().toString();
                         String newip2 = edit_newip2.getText().toString();
                         String newip3 = edit_newip3.getText().toString();
                         String newip4 = edit_newip4.getText().toString();

                         String newname=  edit_newname.getText().toString();
                        String newip=newip1+"."+newip2+"."+newip3+"."+newip4;
                         urlList.add(new IpBean(newname,"http://"+newip+":"+"8801"+"/",
                                 "http://"+newip+":"+"9099"+"/WebService/Andrews/SaveFaceRecognitionDay.asmx",newip));
//                            items.add(newname);

                            SharedPreferences sp = getSharedPreferences("SP_IPBEAN_List",Activity.MODE_PRIVATE);//创建sp对象
                            Gson gson = new Gson();
                            String jsonStr=gson.toJson(urlList); //将List转换成Json
                            SharedPreferences.Editor editor = sp.edit() ;
                            editor.putString("KEY_PEOPLE_LIST_DATA", jsonStr) ; //存入json串
                            editor.apply() ;  //提交
                            dialogPhone.dismiss();
                        } else {
                            Toast.makeText(MainActivity.this, "不可以为空", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    }
                });
                negativeButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
                        dialogPhone.dismiss();
                    }
                });
            }
        });

        dialogPhone.show();


    }

    public static String getOriginalToken(long timestamp){
//        long timestamp = getTimeStamp();
        String result ="jqsoft892155892138"+timestamp;
        return result;
    }
    public static String getProcessedToken(long timestamp){
        String raw = getOriginalToken(timestamp);
        String result = Md5Tool.hashKey(raw);
        return result;
    }
    public static long getTimeStamp(){
        long acsTime = System.currentTimeMillis();
        return acsTime;
    }
    /**
     * 删除公卫的底片
     */
    private void deletephoto(){
        String methodName ="DeleteRecognitionInfoLog";
        JSONObject data = new JSONObject();
        try {
        data.put("iCollectionType",getBase64String("4"));//类型(1:人脸识别 2: 人证核验 3:身份证 4:删除人脸记录 5:删除有效期记录) (Base64加密)
        data.put("sCardNo",getBase64String(etIdCardToDelete.getText().toString().trim()));  /// 身份证号码 (Base64加密)
        data.put("sPersonID",getBase64String(""));//健康档案唯一标识 (Base64加密)
        data.put("sLoginName",getBase64String("DeleteTool"));//用户登录名 (Base64加密)
        data.put("sInputOrgCode",getBase64String(""));// 录入机构主键 (Base64加密)
        data.put("Photo_Base",headBase64String);// 删除的底片(图片Base64值)
        data.put("sRemark",getBase64String(et_reason_for_delete.getText().toString()));// 删除的原因
        data.put("sUserName",getBase64String("删除工具"));//

            if(BphsConstants.appweburltype==2){
                String request = Node.getRequestParams(methodName, data.toString() );
                mPresenter.runNoteGuizhou(request,baseurl);
            }else {
                String request = Node.getRequestParams(methodName, data.toString(),"" );
                mPresenter.runNote(request,baseurl);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }


/**
 *
 * 加载底片
 * */
private String headBase64String;
private String sMessage="";
RequestCall loadHeadImageCall;
    private void loadIDCardNumberHeadImageInfo(final String idNumber){
        long timestamp =  System.currentTimeMillis();
        String timestampString = String.valueOf(timestamp);
        String raw = getOriginalToken(timestamp);
        String result = Md5Tool.hashKey(raw);
        String token = result;
        Map<String, String> params = new HashMap<>();
        params.put("acs_token", token);
        params.put("acs_time", timestampString);
        params.put("idnum", idNumber);
        String GerVerufucationUrl = url+"verification";

        loadHeadImageCall = OkHttpUtils.post()//
                .url(GerVerufucationUrl)//
                .params(params)//
                .build();//
        loadHeadImageCall.execute(new MyResultCallback<IDCardNumberVerificationBean>() {

            @Override
            public void onSuccess(IDCardNumberVerificationBean response) {
//                Util.hideGifProgressDialog(HeadCollectActivity.this);

                if (response!=null && "1".equals(response.getRespond())){

                    Log.i("chenxu", "HeadCollectActivity onSuccess");
                    String idNumExist = response.getIdnumExist();
                    if ("true".equals(idNumExist)){

                         headBase64String = response.getHeadImg();
                        iv_passin_head.setImageBitmap(base64ToBmp(headBase64String));
                        myhandler.sendEmptyMessage(4);

                    } else {
                        myhandler.sendEmptyMessage(4);
//                        requestFaceArchiveCreation();
                        sMessage="不存在对应身份证号码的人脸档案";
                        myhandler.sendEmptyMessage(5);
                        btnDeleteArchive.end("删除人脸档案");

                    }
                } else {
                    myhandler.sendEmptyMessage(4);
                    String suffix = "";
                    if (response!=null){
                        String message = response.getMessage();
//                        message=Util.trimString(message);
                        suffix=":"+message;
                    }
                    String ultimateString = "加载头像失败"+suffix;
                    Log.i("chenxu", "HeadCollectActivity failure");
                    showNotificationDialog(ultimateString, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
//                              returnFailure();
                        }
                    });
                }
            }

            @Override
            public void onFailure(Exception e) {
                myhandler.sendEmptyMessage(4);
                Log.i("10", "HeadCollectActivity onFailure:"+e.getMessage());
//                hideGifProgressDialog(MainActivity.this);

                String suffix = "";
                String ultimateString = "加载头像失败"+suffix;
                showNotificationDialog(ultimateString, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        returnFailure();
                    }
                });
            }
        });
    }

    public static Bitmap base64ToBmp(String source){
        //将字符串转换成Bitmap类型
        Bitmap bitmap=null;
        try {
            byte[]bitmapArray;
            bitmapArray= android.util.Base64.decode(source, android.util.Base64.DEFAULT);
            bitmap= BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;

    }


    public static String getBase64String(String s) {
        if (isBlank(s)) {
            return "";
        } else {
            return Base64.encode(s);
        }
    }
    public static boolean isBlank(String str) {
        return (str == null || str.trim().length() == 0);
    }

    private Handler myhandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 0:
                  Toast.makeText(MainActivity.this,"未获取到返回信息!检查网络连接",Toast.LENGTH_SHORT).show();
                    break;
                case 1:
                    Toast.makeText(MainActivity.this,"身份证号和地址不能为空!",Toast.LENGTH_SHORT).show();
                    break;
                case DELETETIME_MESSAGE:
                    Toast.makeText(MainActivity.this,DeleteTimeMessage,Toast.LENGTH_SHORT).show();
                    break;
                case  4:


                    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,R.style.Theme_AppCompat_Light_Dialog_Alert);
                    builder.setTitle("温馨提示");
                    builder.setMessage("确定删除   "+etIdCardToDelete.getText().toString()+"  人脸服务器上的底片信息吗？");
                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {

                                deleteArchive();

                        }});

                    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                        }
                    });
                    AlertDialog dialog =builder.create();
                    dialog.setCancelable(true);
                    dialog.setCanceledOnTouchOutside(true);
                    dialog.show();

                    break;
                case  5:
                    Toast.makeText(MainActivity.this,sMessage,Toast.LENGTH_SHORT).show();
                    break;
            }

        }
    };
    private void showNotificationDialog(String msg, DialogInterface.OnClickListener positiveListener){
        try {
            if (!isFinishing()) {
                new android.support.v7.app.AlertDialog.Builder(this)
                        .setTitle("")
                        .setMessage(msg)
                        .setPositiveButton("确定", positiveListener)
                        .show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private String[] mVals = new String[]
            {"底片不清晰", "人拍错了", "人脸总是过不去","采集不规范", "其他原因"};
    private void initdatasing() {


        search_page_flowlayout.setAdapter(new TagAdapter<String>(mVals) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                LayoutInflater mInflater = LayoutInflater.from(MainActivity.this);
                TextView tv = (TextView) mInflater.inflate(R.layout.tv,
                        search_page_flowlayout, false);
                tv.setText(s);

                return tv;
            }
        });

        search_page_flowlayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent)
            {

                int s1= search_page_flowlayout.getSelectedList().size();
                if(s1==0){
                    et_reason_for_delete.setText("");
                }else {
                    et_reason_for_delete.setText(mVals[position]);
                }

                return true;
            }
        });

        search_page_flowlayout.setOnSelectListener(new TagFlowLayout.OnSelectListener()
        {
            @Override
            public void onSelected(Set<Integer> selectPosSet)
            {

            }

        });

    }



    @Override
    public void onDeletFaceSuccess(HttpResultBaseGWBean<String> bean) {
        Util.hideGifProgressDialog(MainActivity.this);
        Toast.makeText(MainActivity.this,bean.getsMessage(),Toast.LENGTH_LONG).show();

    }

    @Override
    public void onDeleteFailure(String message) {
        Toast.makeText(MainActivity.this,message,Toast.LENGTH_LONG).show();
    }




    @Override
    protected void initInject() {
        MyApplivation.get(this)
                .getAppComponent()
                .addPeopleBaseInfoFragment(new PeopleBaseInfoFragmentModule(this))
                .inject(this);
    }

}
